package juc;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author DengZhiYuan
 * @version 1.0
 * @date 2023/5/17 19:17
 */
public class ConditionExample {

    private List<String> goodsList = new ArrayList<>();

    private Lock lock = new ReentrantLock();


    private void test(){
        /**
         * 生产者消费者模型代码
         */
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
//                while (true) {
//                    lock.lock();
//                    try {
//                        while (goodsList.size() == maxCount) {
//                            System.out.println("生产者先等等。。。");
//                            condition.await();
//                        }
//                        Thread.sleep(30);
//                        goodsList.add(++a);
//                        System.out.println("生产者生产商品：" + a);
//                        condition.signal();
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    } finally {
//                        lock.unlock();
//                    }
//                }
            }
        });

    }


}
